package com.gupaoedu.user;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: chenhs
 * @date: Created in 16:51 2020/1/6
 **/
public class RpcProxyServer {

    private static final ExecutorService executorService = Executors.newFixedThreadPool(10);

    public void publisher(Object service, int port) {

        ServerSocket serverSocket = null;

        try {
            serverSocket = new ServerSocket(port);

            while (true) {
                Socket socket = serverSocket.accept();
                System.out.println("收到客户端连接："+ socket.getPort());

                //IO过程
                //线程池（异步）
                executorService.submit(new ProcessorHandler(socket, service));
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
